package com.seal.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.seal.dao.BaseDaoImpl;
import com.seal.dao.ISeqRoleDao;
import com.seal.dto.SeqRoleDto;
import com.seal.model.SeqRole;

@Repository("seqRoleDaoImpl")
public class SeqRoleDaoImpl extends BaseDaoImpl implements ISeqRoleDao{

	public void addSeqRole(SeqRole ca) throws Exception {
		this.save(ca);
	}

	@SuppressWarnings("unchecked")
	public List<SeqRole> getSeqRoleList(SeqRoleDto dto) throws Exception {
		StringBuffer hql = new StringBuffer("from SeqRole t where 1=1");
		hql.append(" and t.companyId = :companyId");
		
		if (dto.getSeqLen() !=null) {
			hql.append(" and t.seqLen = :seqLen");
		}
		
		if (dto.getType() !=null) {
			hql.append(" and t.type = :type");
		}
		
		if (dto.getSeqChar() !=null && !"".equals(dto.getSeqChar())) {
			hql.append(" and t.seqChar = :seqChar");
		}

		Query query = this.getSession().createQuery(hql.toString());
		query.setProperties(dto);
		return query.list();
	}

	public SeqRole getSeqRoleById(Long id) throws Exception {
		return (SeqRole) this.select(SeqRole.class, id);
	}

	public void updateSeqRole(SeqRole ca) throws Exception {
		this.update(ca);
	}
}
